<script setup lang="ts">
// 完成一次接口调用
/*
 1：下载axios
 2:导入axios
 3:进入页面调用接口获取数据
 4:存储数据并打印

*/
import axios from 'axios'
let list: {
  id: number
  name: string
}[] = []
const getData = async () => {
  // axios它内部已定义好泛型处理
  // axios<T,R={config,...,data:T}>()=>Promise<R>
  const res = await axios<
    any,
    {
      data: {
        data: {
          channels: { id: number; name: string }[]
        }
      }
    }
  >({
    url: 'http://geek.itheima.net/v1_0/channels'
  })
  list = res.data.data.channels
  console.log(list)
}
getData()
</script>

<template>
  <div></div>
</template>

<style scoped></style>
